package fw_redis

import (
	"context"
	"github.com/redis/go-redis/v9"
	"wms-server/fw/fw_config"
	"wms-server/fw/fw_log"
)

var redisClient *redis.Client

func RedisInit() {
	redisClient = redis.NewClient(&redis.Options{
		Addr:     fw_config.GetConfigHandler().GetString("redis.host"),
		Password: fw_config.GetConfigHandler().GetString("redis.password"),
		DB:       fw_config.GetConfigHandler().GetInt("redis.database"),
	})
	pong, err := redisClient.Ping(context.Background()).Result()
	if err != nil {
		fw_log.Slogger.Info(err.Error())
	} else {
		fw_log.Slogger.Info(pong)
	}
}

func GetRedisHandle() *redis.Client {
	return redisClient
}
